package cn.wgx.modules.sys.web;

import cn.wgx.commons.annotation.ApiPermission;
import cn.wgx.commons.util.Validation;
import cn.wgx.modules.base.web.BaseController;
import cn.wgx.modules.sys.entity.SysUser;
import cn.wgx.modules.sys.entity .SysUserJourney;
import cn.wgx.modules.sys .services.SysUserJourneyService;
import cn.wgx.modules.sys.util.UserUtil;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "2.3 个人历程")
@RestController
@RequestMapping(path = "api/sysUserJourney")
public class SysUserJourneyController extends BaseController{

    @Resource
    SysUserJourneyService service;

    @ApiOperation(value = "列表", notes = "默认获取本人历程. 可选参数: uid(查看他人历程)" )
    @ApiPermission(false)
    @RequestMapping(path = "list", method = RequestMethod.GET)
    public Map<String, Object> getList(
            @RequestParam(required = false) Integer uid,
			@RequestParam(value = "page", required = false, defaultValue = "1")Integer page,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10")Integer pageSize,
            @ApiParam(value = "是否倒序,默认是")@RequestParam(defaultValue = "true", required = false)Boolean desc
        ) {
        SysUserJourney record = new SysUserJourney();
        if(Validation.isNullOrZero(uid)){
            SysUser user = UserUtil.getUser();
            record.setCreateUserId(user.getUser_id());
        }else{
            record.setCreateUserId(uid);
        }
        return returnData(PageHelper.startPage(page, Math.min(Math.abs(pageSize), maxPageSize)), service.getList(record, desc));
//        return returnData(service.getList(record, desc));
    }

    public List<SysUserJourney> getTestData(){
        List<SysUserJourney> list = Lists.newArrayList();
        SysUserJourney sysUserJourney = new SysUserJourney();
        sysUserJourney.setTitle("加入教学平台");
        sysUserJourney.setContent("注册账户");
        SysUserJourney sysUserJourney2 = new SysUserJourney();
        sysUserJourney2.setTitle("考试得分");
        sysUserJourney2.setContent("考试的了不错的分数");
        list.add(sysUserJourney);
        list.add(sysUserJourney2);
        return list;
    }
//
//    @ApiOperation(value = "获取单个", notes = "" )
//    @ApiPermission
//	@RequestMapping(path = "get", method = RequestMethod.GET)
//    public Map<String, Object> getOne(Integer id) {
//		return returnData(service.getOne(id));
//    }
//
//
//    @ApiOperation(value = "新建", notes = "必须参数: " )
//    @ApiPermission
//    @RequestMapping(path = "add", method = RequestMethod.POST)
//    public Map<String, Object> insertOne(@RequestBody SysUserJourney record) {
//        return returnData(service.insertOne(record));
//    }
//
//
//    @ApiOperation(value = "修改", notes = "" )
//    @ApiPermission
//    @RequestMapping(path = "update", method = RequestMethod.PATCH)
//    public Map<String, Object> updateOne(@RequestBody SysUserJourney record) {
//        return returnData(service.updateOne(record));
//
//    }
//
//
//    @ApiOperation(value = "删除", notes = "" )
//    @ApiPermission
//    @RequestMapping(path = "del/{id}", method = RequestMethod.DELETE)
//    public Map<String, Object> deleteOne(@PathVariable("id") Integer id) {
//        return returnData(service.deleteOne(id));
//    }

	

}